<?php
//首页
if(!defined('IN_T')){
	die('hacking attempt');
}

$recommend = get_index_recommend();
$new_recommend = get_new_recommend();
$slide = get_index_slide();

if(Common::is_mobile_visit()){
	$tp->assign('is_mobile',true);
	$slide = array();
	foreach($new_recommend as $k=>$v){
		$slide[] = array(
		'img_name'=>$v['name'],
		'img_path'=>$v['thumb_path'],
		'link'=>$_lang['host'].'tour/'.$v['view_uuid'],
		);
	}
}

$tp->assign('recommend',$recommend);
$tp->assign('slide',$slide);
$tp->assign('index_top_ad',Transaction::get_ad_by_postion(1));
$tp->assign('index_right_ad',Transaction::get_ad_by_postion(4));
//三张推荐全景图片
// var_dump(get_new_vido());
$tp->assign('new_recommend',$new_recommend);
if($_REQUEST['debug']){
		var_dump(Transaction::get_partner());
		// var_dump(Transaction::get_link());
	}
$tp->assign('new_media',get_new_media());
$tp->assign('recommend_vido',get_recommend_vido());
$tp->assign('new_vido',get_new_vido());
//浏览偏航
$tp->assign('browsing_num',get_browsing_num());


//提取首页推荐图片
function get_index_recommend(){
	$sql = "select name,thumb_path,view_uuid,profile,browsing_num ".
	       "from ".$GLOBALS['Base']->table('worksmain')." where recommend=1 order by sort asc, pk_works_main desc limit 27";
	$res = $GLOBALS['Db']->query($sql);
	return $res;
}

//提取首页幻灯片
function get_index_slide(){
	$sql = "select img_name,img_path,link,sort_order ".
	       "from ".$GLOBALS['Base']->table('slide')." order by sort_order asc, id desc";
	$res = $GLOBALS['Db']->query($sql);
	return $res;
}

//提取最新推荐的全景前三个
function get_new_recommend(){
	$sql = "select name,thumb_path,view_uuid from ".$GLOBALS['Base']->table('worksmain')." where recommend = 1 order by pk_works_main desc limit 3";

	$res = $GLOBALS['Db']->query($sql);

	return $res;
}

//提取最热的两个全景图片
// function get_hot_pic(){
// 	$sql = "select name,thumb_path,view_uuid from ".$GLOBALS['Base']->table('worksmain')." order by browsing_num desc limit 2";

// 	$res = $GLOBALS['Db']->query($sql);

// 	return $res;
// }

//提取最新的媒体数据6条
function get_new_media(){
	$sql = "select name,view_uuid from ".$GLOBALS['Base']->table('worksmain')." as w left join ".$GLOBALS['Base']->table('tag_works')." as t on w.pk_works_main=t.works_id  WHERE t.tag_id= 62  order by pk_works_main desc limit 6";

	// echo $sql;
	$res = $GLOBALS['Db']->query($sql);

	return $res;
}

//提取最新的推荐视频6条
function get_recommend_vido(){
	$sql = "select * from ".$GLOBALS['Base']->table('video')." where recommend = 1 order by id desc limit 6";
	// echo $sql;
	$res = $GLOBALS['Db']->query($sql);

	return $res;
}

//提取最新的推荐视频6条
function get_new_vido(){
	$sql = "select * from ".$GLOBALS['Base']->table('video')." order by id desc limit 6";
	// echo $sql;
	$res = $GLOBALS['Db']->query($sql);

	return $res;
}

//浏览排行榜
function get_browsing_num(){

	$sql = "select name,view_uuid,date(photo_date) as time,thumb_path from ".$GLOBALS['Base']->table('worksmain')."  order by browsing_num desc limit 6";

	// echo $sql;
	$res = $GLOBALS['Db']->query($sql);

	return $res;
}
?>